Fix `ostree admin kargs edit-in-place` fails issue
authorHuijing Hei <hhei@redhat.com>
Fri, 8 Jul 2022 11:37:37 +0000 (19:37 +0800)
committerHuijing Hei <hhei@redhat.com>
Tue, 12 Jul 2022 08:27:00 +0000 (16:27 +0800)
Add func to set kernel arguments in place, instead of create new
deployment
Fix https://github.com/ostreedev/ostree/issues/2664

apidoc/ostree-sections.txt
src/libostree/libostree-devel.sym
src/libostree/ostree-sysroot-deploy.c
src/libostree/ostree-sysroot.h
src/ostree/ot-admin-kargs-builtin-edit-in-place.c

index 5af8e687739e00eaff8955f7916cf646bab2b1bf..900e17043045f2a7e771fc0ffe43b7489591cd19 100644 (file)
@@ -577,6 +577,7 @@ ostree_sysroot_get_repo
 ostree_sysroot_get_staged_deployment
 ostree_sysroot_init_osname
 ostree_sysroot_deployment_set_kargs
+ostree_sysroot_deployment_set_kargs_in_place
 ostree_sysroot_deployment_set_mutable
 ostree_sysroot_deployment_unlock
 ostree_sysroot_deployment_set_pinned
index 54945ecaf684beb18a22bd42eb91bad2822b2b8f..145ec1ec5fd52242fd0f43620d758b44b1f92a41 100644 (file)
@@ -23,6 +23,7 @@
 LIBOSTREE_2022.5 {
 global:
   ostree_kernel_args_append_if_missing;
+  ostree_sysroot_deployment_set_kargs_in_place;
 } LIBOSTREE_2022.4;
 
 /* Stub section for the stable release *after* this development one; don't
index 456b0c041d3ed82f79a840258696ca60521490a9..a9d41258f820f7121bda68292f42961d6a992c86 100644 (file)
@@ -3589,6 +3589,49 @@ ostree_sysroot_deployment_set_kargs (OstreeSysroot     *self,
   return TRUE;
 }
 
+/**
+ * ostree_sysroot_deployment_set_kargs_in_place:
+ * @self: Sysroot
+ * @deployment: A deployment
+ * @kargs_str: (allow none): Replace @deployment's kernel arguments
+ * @cancellable: Cancellable
+ * @error: Error
+ *
+ * Replace the kernel arguments of @deployment with the values in @kargs_str.
+ */
+gboolean
+ostree_sysroot_deployment_set_kargs_in_place (OstreeSysroot     *self,
+                                              OstreeDeployment  *deployment,
+                                              char              *kargs_str,
+                                              GCancellable      *cancellable,
+                                              GError           **error)
+{
+  if (!_ostree_sysroot_ensure_writable (self, error))
+    return FALSE;
+
+  g_assert (!ostree_deployment_is_staged (deployment));
+
+  OstreeBootconfigParser *new_bootconfig = ostree_deployment_get_bootconfig (deployment);
+  ostree_bootconfig_parser_set (new_bootconfig, "options", kargs_str);
+
+  g_autofree char *bootconf_name =
+    g_strdup_printf ("ostree-%d-%s.conf",
+                     self->deployments->len - ostree_deployment_get_index (deployment),
+                     ostree_deployment_get_osname (deployment));
+
+  g_autofree char *bootconfdir = g_strdup_printf ("loader.%d/entries", self->bootversion);
+  glnx_autofd int bootconf_dfd = -1;
+  if (!glnx_opendirat (self->boot_fd, bootconfdir, TRUE, &bootconf_dfd, error))
+    return FALSE;
+
+  if (!ostree_bootconfig_parser_write_at (new_bootconfig,
+                                          bootconf_dfd, bootconf_name,
+                                          cancellable, error))
+    return FALSE;
+
+  return TRUE;
+}
+
 /**
  * ostree_sysroot_deployment_set_mutable:
  * @self: Sysroot
index c240aaa06b03285f32ac720f9c312989722bb33e..0cde9e4423e7581204fc4f6b33d93e0635fd14af 100644 (file)
@@ -175,6 +175,13 @@ gboolean ostree_sysroot_deployment_set_kargs (OstreeSysroot     *self,
                                               GCancellable      *cancellable,
                                               GError           **error);
 
+_OSTREE_PUBLIC
+gboolean ostree_sysroot_deployment_set_kargs_in_place (OstreeSysroot     *self,
+                                                       OstreeDeployment  *deployment,
+                                                       char              *kargs_str,
+                                                       GCancellable      *cancellable,
+                                                       GError           **error);
+
 _OSTREE_PUBLIC
 gboolean ostree_sysroot_write_deployments (OstreeSysroot     *self,
                                            GPtrArray         *new_deployments,
index 40ada02fc6a800b946b6a8706e4523819fcb236d..2a16da9c96d7d5f5b929ac3365d20186b1fefe20 100644 (file)
@@ -67,11 +67,10 @@ ot_admin_kargs_builtin_edit_in_place (int argc, char **argv, OstreeCommandInvoca
             }
         }
       
-      g_auto(GStrv) kargs_strv = ostree_kernel_args_to_strv (kargs);
+      g_autofree char *new_options = ostree_kernel_args_to_string (kargs);
       
-      if (!ostree_sysroot_deployment_set_kargs (sysroot, deployment,
-                                              kargs_strv,
-                                              cancellable, error))
+      if (!ostree_sysroot_deployment_set_kargs_in_place (sysroot, deployment, new_options, 
+                                                         cancellable, error))
         return FALSE;
       
     }